package com.raja.servingStation.service.impl;
import com.alibaba.fastjson.JSONObject;
import com.raja.servingStation.common.constant.MysqlPageVo;
import com.raja.servingStation.common.util.IdGenerator;
import com.raja.servingStation.dao.TbOrderDao;
import com.raja.servingStation.entity.ComponentModel;
import com.raja.servingStation.entity.FaultDiacrisis;
import com.raja.servingStation.entity.RepairOrder;
import com.raja.servingStation.entity.RepairPlan;
import com.raja.servingStation.service.TbOrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;


/**工单的service
 * Created by liuyanjun
 * on 2017/4/20.
 */
@Service
public  class TbOrderServiceImpl implements TbOrderService {

    @Autowired
    private TbOrderDao tbOrderDao;
    @Autowired
    IdGenerator idGenerator;


    @Override
    public String selectMaxId() throws Exception {
        return tbOrderDao.selectMaxId();
    }

    @Override
    public Double queryOrderScore(Long id) throws Exception {
        return tbOrderDao.queryOrderScore(id);
    }

    @Override
    public int queryDaiBanOrderCount(Integer servingStationId) throws Exception {
        return tbOrderDao.queryDaiBanOrderCount(servingStationId,null);
    }

    @Override
    public MysqlPageVo queryListByPage(JSONObject param, MysqlPageVo mysqlPageVo,Integer userId) throws Exception {
        int cout = tbOrderDao.queryDaiBanOrderCount(userId,param.getString("keyWord"));
        mysqlPageVo.setTotal(cout);
        if(cout > 0){
            List<RepairOrder> repairOrders = tbOrderDao.queryDaiBanOrder(mysqlPageVo,userId,param.getString("keyWord"));
            mysqlPageVo.setData(repairOrders);
        }
        return mysqlPageVo;
    }

    @Override
    public String selectFirstOrderMaxId() throws Exception {
        return tbOrderDao.selectFirstOrderMaxId();
    }

    @Override
    public FaultDiacrisis getFaultDiacrisisByOrderId(Integer orderId) throws Exception {
        return tbOrderDao.getFaultDiacrisisByOrderId(orderId);
    }

    @Override
    public List<RepairPlan> getRepairPlansByOrderId(Integer orderId) throws Exception {
        return tbOrderDao.getRepairPlansByOrderId(orderId);
    }

    @Override
    public List<ComponentModel> getComponentsByOrderId(Integer orderId) throws Exception {
        return tbOrderDao.getCompontsByOrderId(orderId);
    }

    @Override
    public int queryOrderIsExit(Integer orderId, Integer orderType) throws Exception {
        return tbOrderDao.queryOrderIsExit(orderId,orderType);
    }


}
